home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4410 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.6 KB  |  106 lines

  1. Path: news.cencom.net!ns!tanp
  2. From: tanp@ns (Bill Wendling)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Halp! I don't know what I'm doing wrong!
  5. Date: 4 Feb 1996 07:15:25 GMT
  6. Organization: Cen-Com Internet
  7. Message-ID: <4f1med$oio@news.cencom.net>
  8. References: <4eu8sl$f27@aphex.direct.ca>
  9. NNTP-Posting-Host: ns.cencom.net
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Ed Toivanen inexplicably wrote:
  13. } I've been at this for a couple *days* and can't get it to work.
  14. } It's supposed to graph a function entered at the command line,
  15. } eg. "c:\>graph 2 1" should graph out 2x+1 to stdout using the '*'
  16. } character.  Can anybody help me please?
  17. } I'll name all my kids after you!(when I have 'em that is!) 
  18.  
  19. } /*
  20. }         Ed Toivanen
  21. }         Comp3425
  22. }         Assign1
  23. } */
  24.  
  25. } #include <stdio.h>
  26. } #include <stdlib.h>
  27.  
  28. } #define DOMAN 80
  29. } #define DCORR 40/* shift right, to
  30. }  keep in domain of array*/
  31. } #define RANGE 40
  32. } #define RCORR 20/* shift up, to
  33. }  keep in range of array*/
  34.  
  35. } long power(long, int);
  36.  
  37. } int main(int argc, char **argv){
  38. }     long minDomain = -DOMAN/2;
  39. }     long maxDomain = DOMAN/2-1;
  40. }     long minRange = -RANGE/2;
  41. }     long maxRange = RANGE/2-1;
  42. }     static char lin[RANGE][DOMAN];
  43. }     long x, y=0;
  44. }     long degree, argctemp=argc;
  45.  
  46. /*
  47.     Define a temporary variable:
  48.     char **tmp = argv;
  49. */
  50.  
  51. }     if(argc < 2){
  52. }         printf("Usage %s <coefficients>\n", *argv);
  53. }         return(0);
  54. }     }
  55. }          
  56. }     for(x=minDomain; x<maxDomain; x++){
  57. }         degree = argc - 1;
  58. }         while(degree--){
  59. }             y = ((atol(*++argv)) * (power(x, degree))) + y;
  60. /*
  61.     Replace above line with:
  62.         y += ((atol(*++tmp)) * (power(x, degree)));
  63. */
  64. }             if(y > maxRange || y < minRange)
  65. }                 y = 0;
  66. }         }
  67. /*
  68.     Add this line here:
  69.         tmp = argv;
  70. */
  71. }         lin[ y + RCORR][x + DCORR] = '*';
  72. }     }
  73. }      
  74. }     for(y=maxRange; y>minRange; y--){/*from top down*/
  75. }        for(x = minDomain; x < maxDomain; x++){
  76. }           printf("%c", lin[y + RCORR][x + DCORR]);
  77. /*
  78.     You might want to consider changing this to:
  79.         printf("%s", lin[y + RCORR]);
  80. */
  81. }        }
  82. }        printf("\n");
  83. }     }
  84. }     return(0);
  85. } }
  86.  
  87. } long power(long num, int degree){/* for positive, 
  88. } whole powers*/
  89. }     long product = 1L;
  90. }     
  91. }     if(degree==0 && num==0)
  92. }         return(0L);
  93. }     if(degree==0)
  94. }         return(1L);
  95. }     while(degree--){
  96. }         product *= num;
  97. }     }
  98. }     return(product);
  99. } }                      
  100.  
  101.  
  102. --
  103. Bill Wendling         | "Pinky, are you thinking what I'm thinking?"
  104. tanp@ns.cencom.net  | "I think so, Brain, but burlap chafes me so."
  105. "Boom Shanka"       | Finger me for my Geek Code...NOW!
  106.